import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push (location) {
  return originalPush.call(this, location).catch((err) => err)
}
const routes = [
  // 设置路由的名称，命名路由。
  {
    // 配置登录页面路由
    path: '/login',

    name: 'login',
    component: () => import('@/views/login')
  },
  {
    // 配置页面组件布局路由
    path: '/',

    name: 'layout',
    component: () => import('@/views/layout'),
    children: [
      {
        path: '', // 默认子路由
        name: 'home',
        component: () => import('@/views/home/components')
      },
      {
        path: 'qa',
        name: 'qa',
        component: () => import('@/views/qa')
      },
      {
        path: 'video',
        name: 'video',
        component: () => import('@/views/video')
      },
      {
        path: 'my',
        name: 'my',
        component: () => import('@/views/My')
      }
    ]
  },
  {
    path: '/search',
    name: 'search',
    component: () => import('@/views/search')
  },
  {
    path: '/article/:articleId',
    name: 'article',
    component: () => import('@/views/article'),
    // 开启 props 传参，说白了就是把路由参数映射到组件的 props 中
    props: true
  },
  {
    path: '/user/profile',
    name: 'user',
    component: () => import('../views/user-profile/index.vue')
  }
]

const router = new VueRouter({
  routes
})

export default router
